package cn.aitrox.ry.service.auth.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.auth.dao.AuthGroupUserDao;
import cn.aitrox.ry.service.auth.entity.AuthGroupUserEntity;
import cn.aitrox.ry.service.auth.mapper.AuthGroupUserMapper;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class AuthGroupUserDaoImpl extends BaseDaoImpl<AuthGroupUserEntity> implements AuthGroupUserDao {

    @Autowired
    private AuthGroupUserMapper mapper;

    @Override
    public void deleteByGroupId(Integer groupId) {
        mapper.deleteByGroupId(groupId);
    }

    @Override
    public void batchInsert(List<AuthGroupUserEntity> list) {
        super.batchInsert(list, 1000, new MapperSqlCallback<AuthGroupUserEntity>() {
            @Override
            public void batchInsert(List<AuthGroupUserEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public void deleteByGroupIdUserIds(Integer groupId, List<Integer> userIds) {
        mapper.deleteByGroupIdUserIds(groupId, userIds);
    }

    @Override
    public List<AuthGroupUserEntity> findByUserIds(List<Integer> userIds) {
        if(ArrayUtil.isEmpty(userIds)) {
            return new ArrayList<>();
        }
        return mapper.findByUserIds(userIds);
    }

    @Override
    public List<AuthGroupUserEntity> findByGroupIds(List<Integer> groupIds) {
        return mapper.findByGroupIds(groupIds);
    }

}
